﻿using DLL.NetStandard.FlushRobot.MS.Entity.Param;

using Prism.Commands;
using Prism.Events;
using Prism.Mvvm;
using Prism.Regions;
using DLL.NET70.Infrastructure.Prism;
using DLL.NET70.Infrastructure.Prism.MVVM;
using System;
using System.Collections.Generic;
using System.Linq;

namespace PrismModule.MultyStationRobot.ViewModels
{
    public class PUC_MS_WorkConfigParamViewModel : CMVVMBase, IRegionMemberLifetime
    {
        #region variable

        private CMS_WorkConfigParam _obj = new CMS_WorkConfigParam();

        public CMS_WorkConfigParam Obj
        {
            get { return _obj; }
            set { SetProperty(ref _obj, value); }
        }

        #endregion variable

        #region navigate

        public bool KeepAlive
        {
            get
            {
                //return false;//这个的作用是，只要离开当前切面，就注销掉当前页面
                return false;//这个的作用是，只要离开当前切面，就注销掉当前页面
            }
        }

        public override void Loaded()
        {
            RegisterSaveCommand();//为复合指令绑定相应函数
            base.Loaded();
        }

        public override void UnLoaded()
        {
            UnRegisterSaveCommand();//为复合指令绑定相应函数
            base.UnLoaded();
        }

        public override void Save()
        {
            //获取当前页面的数据
            CMS_WR_WorkConfigParam wrparam = new CMS_WR_WorkConfigParam();
            wrparam.Param = Obj;
            wrparam.SaveParam();
            LogMessage("配置参数保存完成");
        }

        #endregion navigate

        public PUC_MS_WorkConfigParamViewModel(IRegionManager regionManager,
            IEventAggregator eventAggregator,
            IApplicationCommands applicationCommands) :
            base(regionManager, eventAggregator, applicationCommands)
        {
            CMS_WR_WorkConfigParam wrparam = new CMS_WR_WorkConfigParam();
            bool ret = wrparam.ReadParam();
            if (true == ret)
            {
                Obj = wrparam.Param;
            }
            Title = "配置参数";
        }
    }
}